package com.tianq.home.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.tianq.home.domain.Sensor;
import com.tianq.home.service.ISensorService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 终端原始数据记录Controller
 * 
 * @author tianq
 * @date 2025-05-06
 */
@RestController
@RequestMapping("/home/sensor")
public class SensorController extends BaseController
{
    @Autowired
    private ISensorService sensorService;

    /**
     * 查询终端原始数据记录列表
     */
    @PreAuthorize("@ss.hasPermi('home:sensor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sensor sensor)
    {
        startPage();
        List<Sensor> list = sensorService.selectSensorList(sensor);
        return getDataTable(list);
    }

    /**
     * 导出终端原始数据记录列表
     */
    @PreAuthorize("@ss.hasPermi('home:sensor:export')")
    @Log(title = "终端原始数据记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Sensor sensor)
    {
        List<Sensor> list = sensorService.selectSensorList(sensor);
        ExcelUtil<Sensor> util = new ExcelUtil<Sensor>(Sensor.class);
        util.exportExcel(response, list, "终端原始数据记录数据");
    }

    /**
     * 获取终端原始数据记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('home:sensor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(sensorService.selectSensorById(id));
    }

    /**
     * 新增终端原始数据记录
     */
    @PreAuthorize("@ss.hasPermi('home:sensor:add')")
    @Log(title = "终端原始数据记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Sensor sensor)
    {
        return toAjax(sensorService.insertSensor(sensor));
    }

    /**
     * 修改终端原始数据记录
     */
    @PreAuthorize("@ss.hasPermi('home:sensor:edit')")
    @Log(title = "终端原始数据记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Sensor sensor)
    {
        return toAjax(sensorService.updateSensor(sensor));
    }

    /**
     * 删除终端原始数据记录
     */
    @PreAuthorize("@ss.hasPermi('home:sensor:remove')")
    @Log(title = "终端原始数据记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(sensorService.deleteSensorByIds(ids));
    }
}
